/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * member_kk.java
 *
 * Created on Nov 25, 2012, 1:46:21 PM
 */
package prototype;

import java.sql.SQLException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author ryulong
 */
public class member_kk extends javax.swing.JFrame {

    /** Creates new form member_kk */
    public member_kk() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        internal_member = new javax.swing.JInternalFrame();
        jScrollPane1 = new javax.swing.JScrollPane();
        tabel_member = new javax.swing.JTable();
        jButton5 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        panel_pemesan = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        nama_field = new javax.swing.JTextField();
        id_field = new javax.swing.JTextField();
        alamat_field = new javax.swing.JTextField();
        list = new javax.swing.JButton();
        hapus = new javax.swing.JButton();
        apdetan = new javax.swing.JButton();
        simpan = new javax.swing.JButton();
        telpun_field = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        internal_member.setClosable(true);
        internal_member.setResizable(true);
        internal_member.setFocusable(false);

        tabel_member.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "Id", "Nama", "alamat"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.Object.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        tabel_member.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tabel_memberMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tabel_member);

        jButton5.setMnemonic('k');
        jButton5.setText("kembali");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout internal_memberLayout = new javax.swing.GroupLayout(internal_member.getContentPane());
        internal_member.getContentPane().setLayout(internal_memberLayout);
        internal_memberLayout.setHorizontalGroup(
            internal_memberLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 284, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, internal_memberLayout.createSequentialGroup()
                .addContainerGap(151, Short.MAX_VALUE)
                .addComponent(jButton5)
                .addGap(66, 66, 66))
        );
        internal_memberLayout.setVerticalGroup(
            internal_memberLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(internal_memberLayout.createSequentialGroup()
                .addGap(44, 44, 44)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButton5)
                .addGap(28, 28, 28))
        );

        getContentPane().add(internal_member, new org.netbeans.lib.awtextra.AbsoluteConstraints(-8, 7, 300, 90));

        jPanel1.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jLabel1.setFont(new java.awt.Font("Comic Sans MS", 0, 18));
        jLabel1.setText("SEPEDA-KU");

        jLabel9.setFont(new java.awt.Font("Comic Sans MS", 0, 14));
        jLabel9.setText("Sistem Pengolahan Data Kuliner");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(132, 132, 132)
                        .addComponent(jLabel1))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(83, 83, 83)
                        .addComponent(jLabel9)))
                .addContainerGap(67, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel9))
        );

        getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 360, 70));

        jPanel2.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        jButton3.setMnemonic('b');
        jButton3.setText("Batal");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setMnemonic('k');
        jButton4.setText("Keluar");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(81, 81, 81)
                .addComponent(jButton3)
                .addGap(65, 65, 65)
                .addComponent(jButton4)
                .addContainerGap(88, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton3)
                    .addComponent(jButton4))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        getContentPane().add(jPanel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 330, 360, 50));

        panel_pemesan.setBorder(javax.swing.BorderFactory.createTitledBorder("id_member"));

        jLabel2.setText("Nama :");

        jLabel3.setText("Id :");

        jLabel4.setText("Alamat :");

        nama_field.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nama_fieldActionPerformed(evt);
            }
        });

        id_field.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                id_fieldActionPerformed(evt);
            }
        });

        alamat_field.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                alamat_fieldActionPerformed(evt);
            }
        });

        list.setText("list");
        list.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                listActionPerformed(evt);
            }
        });

        hapus.setText("Hapus");
        hapus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                hapusActionPerformed(evt);
            }
        });

        apdetan.setText("update");
        apdetan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                apdetanActionPerformed(evt);
            }
        });

        simpan.setText("Simpan");
        simpan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                simpanActionPerformed(evt);
            }
        });

        telpun_field.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                telpun_fieldActionPerformed(evt);
            }
        });

        jLabel5.setText("No Telp :");

        javax.swing.GroupLayout panel_pemesanLayout = new javax.swing.GroupLayout(panel_pemesan);
        panel_pemesan.setLayout(panel_pemesanLayout);
        panel_pemesanLayout.setHorizontalGroup(
            panel_pemesanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panel_pemesanLayout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(simpan)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(apdetan)
                .addGap(18, 18, 18)
                .addComponent(hapus)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(list)
                .addGap(225, 225, 225))
            .addGroup(panel_pemesanLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panel_pemesanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(jLabel3)
                    .addComponent(jLabel2)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panel_pemesanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(telpun_field, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(id_field, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(nama_field, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(alamat_field, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(120, Short.MAX_VALUE))
        );
        panel_pemesanLayout.setVerticalGroup(
            panel_pemesanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel_pemesanLayout.createSequentialGroup()
                .addGroup(panel_pemesanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nama_field, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panel_pemesanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(id_field, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panel_pemesanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(alamat_field, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 9, Short.MAX_VALUE)
                .addGroup(panel_pemesanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(telpun_field, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addGap(18, 18, 18)
                .addGroup(panel_pemesanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(simpan)
                    .addComponent(list)
                    .addComponent(apdetan)
                    .addComponent(hapus))
                .addContainerGap())
        );

        getContentPane().add(panel_pemesan, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 87, 360, 180));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void tabel_memberMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabel_memberMouseClicked

}//GEN-LAST:event_tabel_memberMouseClicked

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        internal_member.setVisible(false);
    }//GEN-LAST:event_jButton5ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        this.dispose();
}//GEN-LAST:event_jButton4ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        nama_field.setText(null);
        id_field.setText(null);
        alamat_field.setText(null);
        telpun_field.setText(null);
}//GEN-LAST:event_jButton3ActionPerformed

    private void nama_fieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nama_fieldActionPerformed
        String kode = nama_field.getText();
        member kat = new member();
        kat.setId(kode);
        kat.setAlamat(kode);
        kat.setTelp(kode);
        try {
            mastermind kontrol;
            kontrol = mastermind.mind();
            String nama = kontrol.cari_member(kode);
            id_field.setText(nama);
            String alamat = kontrol.address(kode);
            alamat_field.setText(alamat);
            String nomer = kontrol.cari_nomer(kode);
            telpun_field.setText(nomer);
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(this, "data tidak ada dalam database");
            Logger.getLogger(pesanan_kk.class.getName()).log(Level.SEVERE, null, ex);
        }
}//GEN-LAST:event_nama_fieldActionPerformed

    private void id_fieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_id_fieldActionPerformed
        angka(id_field.getText());
}//GEN-LAST:event_id_fieldActionPerformed

    private void alamat_fieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_alamat_fieldActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_alamat_fieldActionPerformed

    private void listActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_listActionPerformed
        internal_member.setVisible(true);
        listing();
}//GEN-LAST:event_listActionPerformed

    private void hapusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hapusActionPerformed
        String kode = id_field.getText();
        member kat = new member();
        kat.setId(kode);
        try {
            mastermind kontrol;
            kontrol = mastermind.mind();
            kontrol.delete_member(kat);
        } catch (SQLException ex) {
            Logger.getLogger(member_kk.class.getName()).log(Level.SEVERE, null, ex);
            
        }
}//GEN-LAST:event_hapusActionPerformed

    private void apdetanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_apdetanActionPerformed
        // TODO add your handling code here:
        String kode = id_field.getText();
        String nama = nama_field.getText();
        String alamat = alamat_field.getText();
        String telpun = telpun_field.getText();
        member mem = new member();
        mem.setId(kode);
        mem.setNama(nama);
        mem.setAlamat(alamat);
        mem.setTelp(telpun);
        try {
            mastermind kontrol;
            kontrol = mastermind.mind();
            kontrol.transform(mem);
        } catch (SQLException ex) {
            Logger.getLogger(member_kk.class.getName()).log(Level.SEVERE, null, ex);
            
        }
}//GEN-LAST:event_apdetanActionPerformed

    private void simpanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_simpanActionPerformed
        // TODO add your handling code here:
        String nama = nama_field.getText();
        String kode = id_field.getText();
        String add = alamat_field.getText();
        String telp = telpun_field.getText();
        
        
        member mem = new member();
        mem.setId(kode);
        mem.setNama(nama);
        mem.setAlamat(add);
        mem.setTelp(telp);
        try {
            mastermind kontrol;
            kontrol = mastermind.mind();
            kontrol.add_member(mem);
            JOptionPane.showMessageDialog(this, "Data dengan id " + kode + " berhasil disimpan");
            
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(this, "inputan error");
            Logger.getLogger(member_kk.class.getName()).log(Level.SEVERE, null, ex);
            
        }
}//GEN-LAST:event_simpanActionPerformed

    private void telpun_fieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_telpun_fieldActionPerformed
        angka(telpun_field.getText());
}//GEN-LAST:event_telpun_fieldActionPerformed
    public void listing() {
        List<member> hju;
        try {
            hju = mastermind.mind().list();
            tabel_member t = new tabel_member(hju);
            tabel_member.setModel(t);
        } catch (SQLException ex) {
            Logger.getLogger(member_kk.class.getName()).log(Level.SEVERE, null, ex);

        }
    }
            public void angka(String angka) {
        if (!angka.matches("[0-9]*")) {
            JOptionPane.showMessageDialog(this, "Format salah Tolong Isikan angka");
            id_field.setText("");
            telpun_field.setText("");
        }
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new member_kk().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField alamat_field;
    private javax.swing.JButton apdetan;
    private javax.swing.JButton hapus;
    private javax.swing.JTextField id_field;
    private javax.swing.JInternalFrame internal_member;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton list;
    private javax.swing.JTextField nama_field;
    private javax.swing.JPanel panel_pemesan;
    private javax.swing.JButton simpan;
    private javax.swing.JTable tabel_member;
    private javax.swing.JTextField telpun_field;
    // End of variables declaration//GEN-END:variables
}
